<template>
  <div class="login-wrap">
    <div class="login">
      <ValidationObserver v-slot="{ handleSubmit }">
        <form class="login-form" @submit.prevent="handleSubmit(toLogin)">
          <ValidationProvider
            tag="div"
            name="phone"
            rules="phoneRequired|phone"
            v-slot="{ errors }"
          >
            <p class="form-input">
              <label class="el-icon-user user"></label
              ><input placeholder="手机号" type="text" v-model="phone" />
            </p>
            <span class="err-msg">{{ errors[0] }}</span>
          </ValidationProvider>
          <ValidationProvider
            tag="div"
            name="phone"
            rules="passwordRequired|password"
            v-slot="{ errors }"
          >
            <p class="form-input">
              <label class="el-icon-lock lock"></label
              ><input placeholder="请输入密码" type="text" v-model="password" />
            </p>
            <span class="err-msg">{{ errors[0] }}</span>
          </ValidationProvider>
          <button class="login-btn">登&nbsp;&nbsp;&nbsp;录</button>
          <p class="register-btn">
            <router-link to="register">立即注册</router-link>
          </p>
        </form>
      </ValidationObserver>
    </div>
    <div class="login-footer">
      <ul>
        <li>关于我们</li>
        <li>联系我们</li>
        <li>联系客服</li>
        <li>商家入驻</li>
        <li>营销中心</li>
        <li>手机尚品汇</li>
        <li>销售联盟</li>
        <li>尚品汇社区</li>
      </ul>
      <p>地址：北京市昌平区宏福科技园综合楼6层</p>
      <p>京ICP备19006430号</p>
    </div>
  </div>
</template>

<script>
import { ValidationObserver, ValidationProvider } from 'vee-validate'
import '@/utils/validate'
import { mapActions } from 'vuex'
export default {
  name: 'ZLogin',
  components: { ValidationProvider, ValidationObserver },
  data() {
    return {
      phone: '13333334444',
      password: '111111',
    }
  },
  methods: {
    ...mapActions('user', ['login']),
    async toLogin() {
      await this.login(this)
      this.$router.push(this.$route.query.redirect || '/home')
    },
  },
}
</script>

<style lang="less" scoped>
.err-msg {
  position: absolute;
  color: #e93854;
  margin-top: 2px;
}
.login-wrap {
  height: 487px;
  background-color: #e93854;
  min-width: 1260px;
  margin: 25px 0;
}
.login {
  width: 1200px;
  margin: 0 auto;
  height: 100%;
  background-image: url('./images/loginbg.png');
  background-repeat: no-repeat;
  position: relative;
}
.login-form {
  background-color: #fff;
  box-sizing: border-box;
  width: 420px;
  height: 300px;
  position: absolute;
  right: 0px;
  top: 50%;
  transform: translateY(-50%);
  padding: 30px 30px 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
label {
  border: 1px solid #ccc;
  font-size: 28px;
  padding: 0px 7px 0;
  color: #ff4261;
  line-height: 40px;
  border-right: none;
}
input {
  // height: 30px;
  border: 1px solid #ccc;
  width: 100%;
  padding: 5px 10px;
  outline: none;
  font-size: 14px;
}
.form-input {
  display: flex;
}
.login-btn {
  font-size: 16px;
  line-height: 38px;
  outline: none;
  border: none;
  background: #ea4a36;
  color: #fff;
  margin-top: 20px;
}
.register-btn {
  text-align: right;
  font-size: 14px;
  color: #666;
  cursor: pointer;
}
.register-btn:hover a {
  color: rgb(102, 208, 250);
  text-decoration: underline;
}
.login-footer {
  width: 1260px;
  margin: 0 auto;
}
.login-footer ul {
  display: flex;
  justify-content: center;
  margin-bottom: 15px;
  li {
    border-right: 1px solid #ccc;
    margin-top: 20px;
    padding: 0 20px;
    &:last-child {
      border-right: none;
    }
  }
}
.login-footer p {
  text-align: center;
  line-height: 25px;
}
</style>
